<?php
namespace admin;
use controller;

use model\admin\paymentModel;

class payment extends controller{


    public function index(){

        $filter = [];
        $list = paymentModel::get_list( $filter );

        echo json_encode( $list );

    }

    public function info(){

        $payment_id = $_GET['payment_id'];
        $payment = paymentModel::info( $payment_id );

        if( $payment['code'] ){
            $config = paymentModel::config_get( $payment['code'] );
            if( !empty( $config['config'] ) ){
                $payment['config'] = json_decode($config['config'], true );
            }else{
                $payment['config'] = [];
            }

        }


        echo json_encode( $payment );
    }

    public function edit(){

        $json = [
            'status'=>0,
        ];
        $payment_id = $_GET['payment_id'];

        $data = $_POST;

        $payment_data = [
            'code'      => $_POST['code'],
            'name'      => $_POST['name'],
            'active'    => $_POST['active'],
        ];
        $json['num'] = paymentModel::edit( $payment_id, $payment_data );

        $code = $data['code'];
        $config = $data['config'];
        paymentModel::config_remove( $code );
        paymentModel::config_set( $code, $config );

        echo json_encode( $json );



    }
}